//
// Created by Zhangwj on 2023/9/25.
//

#include "FuncDefNode.h"

std::unique_ptr<FuncDefNode> FuncDefNode::FuncDefParser(Parser &parser) {
    //FuncDef → FuncType Ident '(' [FuncFParams] ')' Block
    std::unique_ptr<FuncDefNode> funcDefNode = std::make_unique<FuncDefNode>();
    funcDefNode->FuncType = FuncTypeNode::FuncTypeParser(parser);
    funcDefNode->Ident = IdentNode::IdentParser(parser);
    if (parser.getLexType(0) == LexType::LPARENT) {
        parser.next();
    }
    if (parser.getLexType(0) != LexType::RPARENT) {
        // [FuncFParams] 存在
        funcDefNode->FuncFParams = FuncFParamsNode::FuncFParamsParser(parser);
    }
    if (parser.getLexType(0) == LexType::RPARENT) {
        parser.next();
    }
    funcDefNode->Block = BlockNode::BlockParser(parser);
    return funcDefNode;
}
